<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>一朵 - 修改密码</title>
  <!-- swiper-2.7css -->
    <link rel="stylesheet" href="__STATIC__/index/js/swiper/idangerous.swiper.css">
  <!-- swiper-2.7js -->
    <script src="__STATIC__/index/js/swiper/idangerous.swiper.min.js"></script>
  <!-- jquery-3.2.1引用 -->
    <script src="__STATIC__/index/js/global/jquery-3.2.1.min.js"></script>
  <!-- 阿里巴巴矢量图库 -->
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_561814_t3316kgx96kcsor.css">
  <!-- 公共头部 脚部 -->
    <link rel="stylesheet" href="__STATIC__/index/css/global/global.css">
  <!-- 超过1200屏幕 -->
    <link rel="stylesheet" media="screen and (min-width: 1200px)" href="__STATIC__/index/css/change_password/change_password1200.css"
    />
  <!-- 1080-1200 -->
    <link rel="stylesheet" media="screen  and (min-width: 1080px) and (max-width: 1199px) " href="__STATIC__/index/css/change_password/change_password1080.css"
    />
  <!-- 960-1080 -->
    <link rel="stylesheet" media="screen  and (min-width: 960px) and (max-width: 1079px) " href="__STATIC__/index/css/change_password/change_password960.css"
    />
  <!-- 768-959 -->
    <link rel="stylesheet" media="screen  and (min-width: 768px) and (max-width: 959px) " href="__STATIC__/index/css/change_password/change_password768.css"
    />
  <!-- 568-767 -->
    <link rel="stylesheet" media="screen  and (min-width: 568px) and (max-width: 767px) " href="__STATIC__/index/css/change_password/change_password568.css"
    />
  <!-- 375-567 -->
    <link rel="stylesheet" media="screen  and (min-width: 375px) and (max-width: 567px) " href="__STATIC__/index/css/change_password/change_password375.css"
    />
  <!-- 小于375-->
    <link rel="stylesheet" media="screen  and (max-width: 374px) " href="__STATIC__/index/css/change_password/change_password320.css"
    />
  <!--一引入layer-->
    <script src="__STATIC__/layer/layer.js"></script>
</head>
<body>
    <form action="{:url('User/edit_password')}" method="post" id="form1">
    <div class="M">
        <div class="m-header">
            <div>
                <span onclick="go_back();">
                    <span class="iconfont icon-xiangzuo" ></span>
                    返回
                </span>
                <span>修改密码</span>
                <span>
                    {if condition="!empty($realname)"}
                        <a href="{:url('User/index')}" class="my" >
                            {$realname}
                        </a>
                    {else /}
                        <a href="{:url('Login/loginin')}">登录</a>
                        <a href="{:url('Login/register')}">注册</a>
                    {/if}
                    <a href="{:url('MyCart/my_cart')}" class="car">
                        <span class="iconfont icon-gouwuche"></span>
                        <span>{$cart_num}</span>
                    </a>
                </span>
            </div>
        </div>
        <div class="m-password">
            <div>
                <span>原密码</span>
                <input type="password" placeholder="请输入原密码" name="old_password" onkeyup="get_old_password(this)">
            </div>
        </div>
        <div class="m-password">
            <div>
                <span>新密码</span>
                <input type="password" placeholder="请输入6-16位新密码" name="password" onkeyup="get_password(this)">
            </div>
        </div>
        <div class="m-password">
            <div>
                <span>确认新密码</span>
                <input type="password" placeholder="请再次输入新密码" name="repassword" onkeyup="get_repassword(this)">
            </div>
        </div>
        <a href="javascript:;" class="m-bottom" onclick="check_form1()">提交信息</a>
    </div>
    </form>

    <form action="{:url('User/edit_password')}" method="post" id="form2">
    <div class="PC">
        <div class="all">
            <div class="headline">
                <div>
                    <a href="{:url('Index/index')}">
                        <img src="__STATIC__/index/img/head/pc_logo.png" alt="">
                    </a>
                    <a href="javascript:;" onclick="go_back()">
                        返回
                    </a>
                </div>
                <div>
                    <a href="{:url('User/index')}">{$user.realname}</a>
                    <span>丨</span>
                    <a href="{:url('Login/logout')}">退出</a>
                </div>
            </div>

            <div class="pc-content">
                <p>修改密码</p>
                <p>
                    <input type="password" placeholder="请输入原密码" name="old_password" onkeyup="get_old_password(this)">
                </p>
                <p>
                    <input type="password" placeholder="请输入6-16位新密码" name="password" onkeyup="get_password(this)">
                </p>
                <p>
                    <input type="password" placeholder="再次输入新密码" name="repassword" onkeyup="get_repassword(this)">
                </p>
                <a href="javascript:;" onclick="check_form2()" class="pc-bottom">确认修改</a>
            </div>
            <p>官网商城 2007-2017, 版权所有 京ICP备888888888号-1</p>
        </div>
    </div>
    </form>
</body>

</html>
<script>
    /**
     * 返回上一页
     */
    function go_back(){
        window.history.back();  //返回上一页

    }
    /**
     * 联动原始密码
     */
    function get_old_password(obj){
        var value = $(obj).val();
        $('input[name=old_password]').val(value);
    }
    /**
     * 联动新密码
     */
    function get_password(obj){
        var value = $(obj).val();
        $('input[name=password]').val(value);
    }

    /**
     * 联动新密码
     */
    function get_repassword(obj){
        var value = $(obj).val();
        $('input[name=repassword]').val(value);
    }

    /**
     * 检查表单
     */
    function check_form1(){
        var reg = /^[a-zA-Z0-9_]{6,16}$/;
        var old_password = $('#form1').find('input[name=old_password]').val();
        var password = $('#form1').find('input[name=password]').val();
        var repassword = $('#form1').find('input[name=repassword]').val();

        if(old_password == ''){
            layer.msg('请输入原始密码',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(password == ''){
            layer.msg('请输入新密码',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(password == ''){
            layer.msg('请输入确认密码', {icon: 2, time: 1500, shade: 0.1}, function (index) {
                layer.close(index);
            });

        }

        if(!reg.test(password)){
            layer.msg('密码格式错误，必须是字母数字下划线6~16位组合',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(password != repassword){
            layer.msg('两次密码输入不一致，请重新输入',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        $.post("{:url('User/edit_password')}",
            {password:password,old_password:old_password,repassword:repassword},
            function(data){
                if(data.code == 1){
                    layer.msg('修改成功，请重新登陆',{icon:1,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                        window.location.href = "{:url('Login/logout')}";
                    });
                }else{
                    layer.msg(data.msg,{icon:2,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                }
            }
        );
    }

    /**
     * 检查表单
     */
    function check_form2(){
        var reg = /^[a-zA-Z0-9_]{6,16}$/;
        var old_password = $('#form2').find('input[name=old_password]').val();
        var password = $('#form2').find('input[name=password]').val();
        var repassword = $('#form2').find('input[name=repassword]').val();

        if(old_password == ''){
            layer.msg('请输入原始密码',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(password == ''){
            layer.msg('请输入新密码',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(password == ''){
            layer.msg('请输入确认密码',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(!reg.test(password)){
            layer.msg('密码格式错误，必须是字母数字下划线6~16位组合',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        if(password != repassword){
            layer.msg('两次密码输入不一致，请重新输入',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
            });
        }

        $.post("{:url('User/edit_password')}",
            {password:password,old_password:old_password,repassword:repassword},
            function(data){
                if(data.code == 1){
                    layer.msg('修改成功，请重新登陆',{icon:1,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                        window.location.href = "{:url('Login/logout')}";
                    });
                }else{
                    layer.msg(data.msg,{icon:2,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                }
            }
        );
    }
</script>